package com.hunan.api.catv.action.member.open;

import com.hunan.api.catv.action.BaseAction;
import com.hunan.api.catv.common.Api;
import com.hunan.api.catv.entity.Result;
import com.hunan.api.catv.entity.po.MemberOpenidInfo;
import com.hunan.api.catv.service.biz.member.open.MemberOpenBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: wangchao
 * @Date: 2020/10/27 14:49
 */
@RestController
@Validated
@RequestMapping(Api.member_open)
public class MemberOpenAction extends BaseAction {

    @Autowired
    MemberOpenBiz memberOpenBiz;

    /**
     * 提供第三方openid映射会员id
     */
    @GetMapping("/getMemberThirdOpenId/{memberId}/{memberType}")
    public Result getMemberThirdOpenId(@PathVariable("memberId") Integer memberId, @PathVariable("memberType") String memberType) {
        return buildOK(memberOpenBiz.getMemberThirdOpenId(memberId, memberType), "");
    }

    /**
     * 通过映射给第三方openid获取会员信息
     */
    @GetMapping("/getMemberInfoByThirdOpenId/{openId}")
    public Result getMemberInfoByThirdOpenId(@PathVariable("openId") String openId) {
        return buildOK(memberOpenBiz.getMemberInfoByThirdOpenId(openId), "");
    }

    /**
     * 修改会员扩展信息
     */
    @PutMapping("/updateMemberOpenInfo")
    public Result updateMemberOpenInfo(@RequestBody MemberOpenidInfo memberOpenidInfo) {
        return buildOK(memberOpenBiz.updateMemberOpenInfo(memberOpenidInfo), "");
    }

    /**
     * 映射会员与极光绑定id
     */
    @PostMapping("/saveMemberAndJgInfo")
    public Result saveMemberAndJgInfo(@RequestBody MemberOpenidInfo memberOpenidInfo, HttpServletRequest request) {
        return buildResult(memberOpenBiz.saveMemberAndJgInfo(memberOpenidInfo, getMemberIdV2(request)));
    }

}
